package org.springblade.application.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springblade.application.command.ApplicationManagementPageCommand;
import org.springblade.application.mapper.ApplicationManagementMapper;
import org.springblade.application.service.IApplicationManagementService;
import org.springblade.applicationapi.entity.ApplicationManagementEntity;
import org.springblade.applicationapi.entity.TargetAddressEntity;
import org.springblade.applicationapi.vo.ApplicationManagementVO;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @Author wzy
 **/
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class ApplicationManagementServiceImpl extends BaseServiceImpl<ApplicationManagementMapper, ApplicationManagementEntity> implements IApplicationManagementService {



	@Override
	public IPage<ApplicationManagementVO> managementPage(ApplicationManagementPageCommand pageCommand, IPage<ApplicationManagementVO> page){

		return page.setRecords(baseMapper.managementPage(page,pageCommand));
	}

	@Override
	public boolean edit(ApplicationManagementEntity entity){
		return this.updateById(entity);
	}

   @Override
	public boolean removeByid(List<Long> ids){
		return this.deleteLogic(ids);
   }

	@Override
	public boolean addPermissions(ApplicationManagementEntity entity){
		//新增应用管理
		List<ApplicationManagementEntity> list = this.lambdaQuery().eq(ApplicationManagementEntity::getTargetAddressId, entity.getTargetAddressId()).list();
		if (list.size()>0 ){
             this.removeByIds(list.stream().map(ApplicationManagementEntity::getId).collect(Collectors.toList()));
		}
		return this.save(entity);
	}

}
